"""
修改：
鸢尾花数据集替换葡萄酒数据集
改算法ID3(entropy)，CART(gini)
测试集占30%
"""
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
# 决策树分类器
from sklearn.tree import DecisionTreeClassifier


def main():
    iris = load_iris()
    x = iris.data
    y = iris.target
    x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3)
    clf = DecisionTreeClassifier(criterion="gini")  # criterion="entropy" 特征=信息增益
    clf.fit(x_train, y_train)
    train_score = clf.score(x_train, y_train)
    test_score = clf.score(x_test, y_test)
    print(f'train score: {train_score: .6f};\n test score: {test_score: .6f};'.format(
        train_score=train_score, test_score=test_score))


if __name__ == '__main__':
    main()
